// xc_lshop/club/clubshop/pro/proinfo.js
// var actbill = require('../../../xc/model/pro_contents')
var html2wxml = require('../../../../html2wxml/html2wxml.js');

var actclubbill = require('../../model/clubshop_pro')
// var actclubbill = require('../../../../')
var actbill = require('../../../../xc/model/pro_contents')
var actcart = require('../../../../xc/sys/cart')

Page({
  mixins: [require('../../../../xc/mixins/basicMixin')],

  /**
   * 页面的初始数据
   */
  data: {
    navlist: [],
    navopacity: 0,
  },

  xcloaddata: function (options, config) {
    this.confgset(config)

    this.getmodel(options.id)
  },
  getmodel(id, activityid) {
    var that = this
    actclubbill.getmodel(id, activityid).then(res => {
 

      if (res.status == 1) {
      
        // html2wxml.html2wxml('article', res.obj.contents.imgs, this, 5);
        var xcmodelobj = res.obj;
        // console.log("xcmodelobj['imgslist']")
        // console.log(!xcmodelobj['imgslist'])

        if(that.data.yihuoconfig && that.data.yihuoconfig['status']==1){
          if(xcmodelobj['imgslist'].length==0 && xcmodelobj['simg']){
            xcmodelobj['imgslist']=[{imgurl:xcmodelobj['simg'],status:1}]
          }
        }
       
        
        that.setData({
          xcmodel: xcmodelobj
        })

        wx.setNavigationBarTitle({
          title: res.obj.name
        });
      }
    })
  },
  buyop: function (ev) {
    var dataset = ev.currentTarget.dataset
    if (!this.data.member.memberinfo) {
      this.login();
      return;
    }

    var that = this
    // var option = {protype:2}; //团长产品
    var option = {protype:2,clubid:this.data.xcmodel.shopid,clubmode:this.data.xcmodel.autarky==1?'4':'2'}; //团长产品
  
    actbill.showattrchose(that, that.data.xcmodel.id, that.data.selected, ev.currentTarget.dataset.op, option)
  },
  // 加购成功事件
  aftercart(e) {
    this.loadcardlength()
  },
  loadcardlength() {
    var that = this

    actcart.loadcartlocal().then(res => {
      if (res.totalnuminfo) {
        that.setData({
          cartlistnum: res.totalnuminfo.totalnum
        })
      }
    })

  },
  toshop(){
    wx.navigateTo({
      url: '/xc_lshop/club/clubshop/index?clubid='+this.data.xcmodel.shopid,
    })
  },
  tocart() {
    wx.navigateTo({
      url: '/xc_lshop/shop/cart/index',
    })
  },
   // 滚动触发事件
 VerticalMain: function (e) {
 


    var that = this;
    let list = that.data.navlist;
    var scrollTop = e.detail.scrollTop


    var updata = {};
    if (scrollTop >= 0 && scrollTop < 200) {
      updata['navopacity'] = scrollTop / 2 * 0.01
    } else {
      if (this.data.navopacity != 1) {
        updata['navopacity'] = 1
      }
    }
    if (scrollTop > 400) {
      updata['backtopshow'] = true
    } else {
      updata['backtopshow'] = false
    }
    that.setData(updata)
    let view = wx.createSelectorQuery().selectAll(".scrollanchor");
    view.boundingClientRect(function (rects) {
      for (var a in rects) {
        if (rects[a].top > 0) {

          if (that.navCur != a) {

            that.setData({
              navCur: parseInt(a),
            })
          }
          break;
        }
      }

    }).exec()

},
callphone(e) {
  wx.makePhoneCall({
    phoneNumber: e.currentTarget.dataset.phone
  })
},
mapnavigation() {
  
  var shopinfo=this.data.xcmodel.shopinfo
  var latitude = parseFloat(shopinfo.lat)
  var longitude = parseFloat(shopinfo.lng)
  var name = shopinfo.title
  var address = shopinfo.province + shopinfo.city + shopinfo.county + shopinfo.addrinfo

  wx.openLocation({
    latitude,
    longitude,
    scale: 18,
    name: name,
    address: address
  })
},

  confgset(config) {
    //主题设置
    var updateconfig = {};
    var unit="￥"
    if(config.yihuo){
      if(config.yihuo.status==1){
        unit=config.payment.balancepayunit
      }
      updateconfig['yihuoconfig'] = config.yihuo
      updateconfig['unit'] = unit
    }
   

    if (config.order) {
      var owngroupstatus = config.order.owngroupstatus
      updateconfig['orderconfig'] = config.order

      updateconfig['owngroupstatus'] = owngroupstatus
      if(config.order.cart){
        updateconfig['cartstatus']=config.order.cart;
      }else{
        updateconfig['cartstatus']=1
      }
    }
    if (config.prothem && config.prothem.themcolor) {
      var themconfig = config.prothem.themcolor.config;
      updateconfig['themconfig'] = themconfig
    }
    if (config.rebate) {
      updateconfig['configrebate'] = config.rebate
    }
    if (config.prothem && config.prothem.detail) {
      var detailconfig = config.prothem.detail.proconfig;  
      var customStyle = config.prothem.detail.customStyle;
      var popconfig = config.prothem.popup.proconfig;
      var popCustomStyle = config.prothem.popup.customStyle;
      updateconfig['detailconfig'] = detailconfig
      updateconfig['customStyle'] = customStyle
      updateconfig['popconfig'] = popconfig
      updateconfig['popCustomStyle'] = popCustomStyle
    }
    console.log(updateconfig)
    this.setData(updateconfig)
    //导航设置
    var commentshow = this.data.commentshow
    if (config.proconfig) {
      commentshow = config.proconfig.pro.commentshow
    }
    var detailconfig = config.prothem.detail.proconfig;
    if (detailconfig.evaluate.status == 1 || detailconfig.moreinfor.status == 1) {
      var navlist = [{
        id: "main",
        name: "商品"
      }]
      if (commentshow != "3" && detailconfig.evaluate.status == 1) {
        navlist.push({
          id: "evaluate",
          name: "评价"
        })
      }
      if (detailconfig.moreinfor.status == 1) {
        navlist.push({
          id: "infor",
          name: "详情"
        })
      }
      // navlist.push({id: "recommend",name: "推荐" })
      this.setData({
        commentshow,
        navlist
      })

    }

  },
  // 注册
  login() {
    var app = getApp()
    var that = this
    app.xc_sys_config.authop.oppower("login").then(function (res) {
      that.setData({
        "member": app.globalData.member
      })
    })
  },
  afterlogin: function (options, config, userinfo) {
    // if (userinfo.memberinfo) {
      this.setData({
        member: userinfo
      })
    // }
  },
  backtop(e) {
    this.setData({
      scrollnavCur: parseInt(0),
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },


})